﻿@{
    string KeyId = WebHelper.HttpHelper.Request.Query["ID"].ToStr();
    KeyId = KeyId.ToGuid() == Guid.Empty ? "" : KeyId;
}
<div id="app">
    <div class="page-content animated fadeInDown">
        <div class="container-fluid  pb-100">
            <div class="row" id="form">
                <!--检索面板-->
                <div class="col-sm-12">
                    <h4 class="example-title">登陆账号</h4>
                    <input type="text" class="form-control" name="userLoginName" id="userLoginName" v-model="userLoginName" placeholder="请输入 登陆名" />
                </div>
                <div class="col-sm-12">
                    <h4 class="example-title">邮箱</h4>
                    <input type="text" class="form-control" name="userEmail" id="userEmail" v-model="userEmail" placeholder="请输入 邮件" />
                </div>
                <div class="col-sm-12">
                    <h4 class="example-title">用户名</h4>
                    <input type="text" class="form-control" name="userName" id="userName" v-model="userName" placeholder="请输入 用户名称" />
                </div>
                <div class="col-sm-12">
                    <h4 class="example-title">登陆密码</h4>
                    <input type="password" class="form-control" name="userPwd" id="userPwd" v-model="userPwd" placeholder="请输入 登陆密码" />
                </div>
            </div>

        </div>
    </div>
    <!--按钮-->
    <div class="my-ButtonBar text-right">
        @*<button type="button" class="btn btn-success" v-show="form__KeyId" onclick="adminForm.resetUrl(null)">新增</button>*@
        <button class="btn btn-primary" onclick="$.sysuser.save()">提交</button>
        <button class="btn btn-danger" onclick="admin.layer.close(admin.getLayerIframeIndex());">关闭</button>
    </div>
</div>
@section css{
}
@section js{
    <!--业务代码-->
    <script type="text/javascript">
     (function ($) {
         var gid = '';
         gid = '@KeyId';
        $.sysuser = {
            load: function (gid) {
                if (gid != "") {
                    $.ajax({
                        type: 'POST',
                        url: '@Url.Action("LoadForm")',
                        data: { ID: gid },
                        dataType: 'JSON',
                        success: function (data) {
                            console.log(data);
                            if (data.type == 3) {
                                alert(data.message);
                            } else {
                                $("#userLoginName").val(data.userLoginName);
                                $("#userEmail").val(data.userEmail);
                                $("#userName").val(data.userName);
                                $("#userPwd").val(data.userPwd);
                            }
                        }
                    });
                }
            },
            save: function () {
                function ExistMessage(data) {
                    if (data.errorcode == 1) {
                        ErrorMessage($('#userLoginName'), data.message);
                    } else if (data.errorcode == 2) {
                        ErrorMessage($('#userEmail'), data.message);
                    } else if (data.errorcode == 3) {
                        ErrorMessage($('#userName'), data.message);
                    } else if (data.errorcode == 4) {
                        ErrorMessage($('#userPwd'), data.message);
                    }
                };
                //提示信息
                function ErrorMessage(e, msg) {
                    $('.txt-error').remove();
                    e.focus();
                    e.after('<label class="txt-error" style="color:red">' + msg + '</label>');
                };
                var userLoginName = $.trim($("#userLoginName").val());
                var userEmail = $.trim($("#userEmail").val());
                var userName = $.trim($("#userName").val());
                var userPwd = $.trim($("#userPwd").val());

                if (userLoginName == "") {
                    ErrorMessage($("#userLoginName"), '请输入账号');
                } else if (userEmail == "") {
                    ErrorMessage($("#userEmail"), '请输入邮箱');
                } else if (userName == "") {
                    ErrorMessage($("#userName"), '请输入用户名');
                } else if (userPwd == "") {
                    ErrorMessage($("#userPwd"), '请输入密码');
                } else {
                    var data = {
                        gid: '@KeyId',
                        userLoginName: userLoginName,
                        userEmail: userEmail,
                        userName: userName,
                        userPwd: userPwd
                    };
                     $.ajax({
                        type: 'POST',
                        url: '@Url.Action("Save")',
                        data: data,
                        dataType: 'JSON',
                        success: function (data) {
                            if (data.type == 1) {
                                var parentName = admin.getParentFrameName();
                                //var _pIframe = top.window.frames[parentName];
                                //if (!_pIframe) parentName = admin.getWinIframe();
                                if (parentName) top.window.frames[parentName].$.userdata.refresh();
                                admin.layer.close(admin.getLayerIframeIndex())
                            } else {
                                ExistMessage(data);
                            }
                        }
                    });
                }
            }
        };
        $(function () {
            $.sysuser.load(gid);
        });
    })(jQuery);
    </script>
}
